package org.p2psimulator.entity.overlaynetwork.routingtable;

import org.p2psimulator.entity.Id;

public class HibridRoutingTable extends RoutingTable{

	
	private ChordFingerTable chordFingerTable;
	
	private GnutellaRoutingTable gnutellaRoutingTable;

	
	
	public HibridRoutingTable(ChordFingerTable chordFingerTable,
			GnutellaRoutingTable gnutellaRoutingTable) {
		super();
		this.chordFingerTable = chordFingerTable;
		this.gnutellaRoutingTable = gnutellaRoutingTable;
	}

	public HibridRoutingTable(int M, Id owner) {
		chordFingerTable = new ChordFingerTable(M, owner);
		gnutellaRoutingTable = new GnutellaRoutingTable();
	}

	public ChordFingerTable getChordFingerTable() {
		return chordFingerTable;
	}

	public void setChordFingerTable(ChordFingerTable chordFingerTable) {
		this.chordFingerTable = chordFingerTable;
	}

	public GnutellaRoutingTable getGnutellaRoutingTable() {
		return gnutellaRoutingTable;
	}

	public void setGnutellaRoutingTable(GnutellaRoutingTable gnutellaRoutingTable) {
		this.gnutellaRoutingTable = gnutellaRoutingTable;
	}

	@Override
	public void clear() {
		this.gnutellaRoutingTable.clear();
		this.chordFingerTable.clear();
		
	}

	@Override
	public boolean contains(Id peer) {
		return this.gnutellaRoutingTable.contains(peer) && this.chordFingerTable.contains(peer);
	}

	@Override
	public boolean deletePeer(Id peer) {
		return	this.gnutellaRoutingTable.deletePeer(peer) && this.chordFingerTable.deletePeer(peer);
	}

	@Override
	public void insertNeighbor(Id peer) {
		this.gnutellaRoutingTable.insertNeighbor(peer);
                this.chordFingerTable.insertNeighbor(peer);
	}

	public int chordTableSize() {
		return this.chordFingerTable.size();
	}
	
	public int gnutellaTableSize(){
		return this.gnutellaRoutingTable.size();
	}
}
